#include <iostream>

#include <log4cpp/Category.hh>
#include <log4cpp/Priority.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>

using std::cout;

using namespace log4cpp;

int main()
{
    //1. 创建日志布局
    PatternLayout * ptn = new PatternLayout();
    ptn->setConversionPattern("%d %c [%p] %m%n");
    PatternLayout * ptn2 = new PatternLayout();
    ptn2->setConversionPattern("%d %c [%p] %m%n");
    //2. 创建日志的目的地
    OstreamAppender * pOsAppender = new OstreamAppender("console", &cout);
    pOsAppender->setLayout(ptn);

    FileAppender * pFileAppender = new FileAppender("fileAppender", "wd.log");
    pFileAppender->setLayout(ptn2);

    //3. 创建日志记录器
    Category & mycat = Category::getInstance("wd");
    //mycat.setPriority(Priority::DEBUG);
    mycat.setPriority(Priority::ERROR);
    mycat.addAppender(pOsAppender);
    mycat.addAppender(pFileAppender);

    //4.记录日志
    mycat.alert("alert message");//
    mycat.crit("crit message");//
    mycat.debug("debug message");//
    mycat.info("info message");//
    mycat.notice("notice message");//
    mycat.error("error message");//

    //5. 回收各种资源
    Category::shutdown();
    return 0;
}
;
